<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // disconnect放在定时器里, 后续还能继续绑定
        const mutationobserver = new MutationObserver(() => {
            console.log('<body attribute changed>')
        })

        mutationobserver.observe(document.body, {attributes: true})

        document.body.setAttribute('className', 'body') // 运行这段代码触发回调

        setTimeout(() => {
            mutationobserver.disconnect()

            document.body.setAttribute('data-myattribute', 'v-data') // 不会执行回调函数
        })

        setTimeout(() => {
            mutationobserver.observe(document.body, {attributes: true})

            document.body.setAttribute('className', 'class') // 触发
        })
    </script>
</body>
</html>